/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.altius.web.controller;

import cc.altius.domain.CustomUserDetails;
import cc.altius.exception.CouldNotSaveToDataBaseException;
import cc.altius.model.*;
import cc.altius.service.CustomerService;
import cc.altius.utils.DateUtils;
import cc.altius.utils.ExcelUtils.BodyRow;
import cc.altius.utils.ExcelUtils.CellInfo;
import cc.altius.utils.ExcelUtils.Parameter;
import cc.altius.utils.ExcelUtils.WorkSheet;
import com.google.gson.Gson;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import jxl.format.Colour;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author santosh
 */
@Controller
@SessionAttributes({"corporateCustommerList", "corporateCustommerEventList", "corporateCustomer"})
public class CorporateController {

    @Autowired
    private CustomerService customerService;

    @ModelAttribute("paymentTypeList")
    List<PaymentType> getPaymentTypeList() {
        return this.customerService.getPaymentTypeList();
    }

    @RequestMapping(value = "/corporate/backToListCorporateCustomer.htm", method = RequestMethod.GET)
    public String showEditCorporateCustomerForBackPage(
            @RequestParam(value = "paymentTypeId", required = true, defaultValue = "0") int paymentTypeId,
            @RequestParam(value = "customerName", required = true, defaultValue = "") String customerName,
            ModelMap map) {
        return "redirect:/corporate/listCorporateCustomer.htm?paymentTypeId=" + paymentTypeId + "&customerName=" + customerName;
    }

    @RequestMapping(value = "/corporate/editCorporateCustomerDetails.htm", method = RequestMethod.GET)
    public String showEditCorporateCustomerPage(
            @RequestParam(value = "corporateCustomerId", required = true, defaultValue = "0") int corporateCustomerId,
            @RequestParam(value = "paymentTypeId", required = true, defaultValue = "0") int paymentTypeId,
            @RequestParam(value = "customerName", required = true, defaultValue = "") String customerName,
            ModelMap map) {
        System.out.println("editCustomer:GET");
        CorporateCustomer corporateCustomer = this.customerService.getCorporateCustomerById(corporateCustomerId);
        map.addAttribute("corporateCustomer", corporateCustomer);
        map.addAttribute("paymentTypeId", paymentTypeId);
        map.addAttribute("corporateCustomerId", corporateCustomerId);

        return "/corporate/editCorporateCustomerDetails";
    }

    @RequestMapping(value = "/corporate/editCorporateCustomerDetails.htm", method = RequestMethod.POST)
    public String editCorporateCustomerPage(
            @ModelAttribute("corporateCustomer") CorporateCustomer corporateCustomer,
            @RequestParam(value = "paymentTypeId", required = true, defaultValue = "0") int paymentTypeId,
            @RequestParam(value = "customerName", required = true, defaultValue = "") String customerName,
            ModelMap map) {
        System.out.println("editCustomer:POST");
        if (corporateCustomer.getCorporate() != null) {
            paymentTypeId = corporateCustomer.getCorporate().getPaymentTypeId();
        }
        int result = this.customerService.editCorporateCustomer(corporateCustomer);
        if (result == 0) {
            return "redirect:/corporate/listCorporateCustomer.htm?msg=Fail to update customer data";
        }
        return "redirect:/corporate/listCorporateCustomer.htm?paymentTypeId=" + paymentTypeId + "&customerName=" + customerName;
    }

    @RequestMapping(value = "/corporate/backToAddCorporateCustomer.htm", method = RequestMethod.GET)
    public String showAddCorporateCustomerForBackPage(HttpSession session, ModelMap map) {
        System.out.println("addCustomer For Back:GET");
        CorporateCustomer corporateCustomer = (CorporateCustomer) session.getAttribute("corporateCustomer");
        map.addAttribute("corporateCustomer", corporateCustomer);
        return "/corporate/addCorporateCustomer";
    }

    @RequestMapping(value = "/corporate/addCorporateCustomer.htm", method = RequestMethod.GET)
    public String showAddCorporateCustomerPage(HttpSession session, ModelMap map) {
        System.out.println("addCustomer:GET");
        session.removeAttribute("corporateCustomer");
        CorporateCustomer corporateCustomer = new CorporateCustomer();
        map.addAttribute("corporateCustomer", corporateCustomer);
        return "/corporate/addCorporateCustomer";
    }

    @RequestMapping(value = "/corporate/addCorporateCustomer.htm", method = RequestMethod.POST)
    public String addCorporateCustomer(@ModelAttribute("corporateCustomer") CorporateCustomer corporateCustomer, ModelMap map) {
        System.out.println("addCustomer:POST");
        map.addAttribute("corporateCustomer", corporateCustomer);
        return "redirect:/corporate/addCorporateCustomerEvent.htm";
    }

    @RequestMapping(value = "/corporate/addCorporateCustomerEvent.htm", method = RequestMethod.GET)
    public String showAddEventPage(HttpSession session, ModelMap map) {
        System.out.println("addEvent:GET");
        CorporateCustomer corporateCustomer = (CorporateCustomer) session.getAttribute("corporateCustomer");
        List<Event> eventList = this.customerService.getEventList(corporateCustomer.getCorporate().getPaymentTypeId());
        CorporateCustomerEvent customerEvent = new CorporateCustomerEvent();
        int id = 0;
        for (Event event : eventList) {
            id++;
            switch (id) {
                case 1: {
                    customerEvent.setEvent1(event);
                    break;
                }
                case 2: {
                    customerEvent.setEvent2(event);
                    break;
                }
                case 3: {
                    customerEvent.setEvent3(event);
                    break;
                }
                case 4: {
                    customerEvent.setEvent4(event);
                    break;
                }
                case 5: {
                    customerEvent.setEvent5(event);
                    break;
                }
                case 6: {
                    customerEvent.setEvent6(event);
                    break;
                }
                case 7: {
                    customerEvent.setEvent7(event);
                    break;
                }
                case 8: {
                    customerEvent.setEvent8(event);
                    break;
                }
                case 9: {
                    customerEvent.setEvent9(event);
                    break;
                }
                case 10: {
                    customerEvent.setEvent10(event);
                    break;
                }
                case 11: {
                    customerEvent.setEvent11(event);
                    break;
                }
                case 12: {
                    customerEvent.setEvent12(event);
                    break;
                }
                case 13: {
                    customerEvent.setEvent13(event);
                    break;
                }
                case 14: {
                    customerEvent.setEvent14(event);
                    break;
                }
                case 15: {
                    customerEvent.setEvent15(event);
                    break;
                }
                default: {
                    System.out.println("Nothing to do");
                }
            }
        }
        map.addAttribute("customerEvent", customerEvent);
        List<EventStatus> eventStatusList = this.customerService.getEventStatusList();
        map.addAttribute("eventStatusList", eventStatusList);

        return "/corporate/addCorporateCustomerEvent";
    }

    @RequestMapping(value = "/corporate/addCorporateCustomerEvent.htm", method = RequestMethod.POST)
    public String addEvent(@ModelAttribute("customerEvent") CorporateCustomerEvent customerEvent, HttpSession session, HttpServletRequest request, ModelMap map) throws ServletRequestBindingException, ParseException {
        System.out.println("addEvent:POST");

        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yy");
        Date eventDate = null;
        Date lastModifiedDate = null;
        User lastModifiedBy = null;

        for (int i = 1; i <= 15; i++) {
            if (!ServletRequestUtils.getStringParameter(request, "scheduleEventT" + i).equals("")) {
                eventDate = sdf.parse(ServletRequestUtils.getStringParameter(request, "scheduleEventT" + i));
                lastModifiedBy = new User();
                lastModifiedBy.setUserId(((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId());
                lastModifiedDate = DateUtils.getCurrentDateObject(DateUtils.IST);

            } else {
                eventDate = null;
                lastModifiedDate = null;
                lastModifiedBy = null;
            }
            switch (i) {
                case 1:
                    customerEvent.setScheduleEvent1(eventDate);
                    customerEvent.setLastModifiedBy1(lastModifiedBy);
                    customerEvent.setLastModifiedDate1(lastModifiedDate);
                    break;
                case 2:
                    customerEvent.setScheduleEvent2(eventDate);
                    customerEvent.setLastModifiedBy2(lastModifiedBy);
                    customerEvent.setLastModifiedDate2(lastModifiedDate);
                    break;
                case 3:
                    customerEvent.setScheduleEvent3(eventDate);
                    customerEvent.setLastModifiedBy3(lastModifiedBy);
                    customerEvent.setLastModifiedDate3(lastModifiedDate);
                    break;
                case 4:
                    customerEvent.setScheduleEvent4(eventDate);
                    customerEvent.setLastModifiedBy4(lastModifiedBy);
                    customerEvent.setLastModifiedDate4(lastModifiedDate);
                    break;
                case 5:
                    customerEvent.setScheduleEvent5(eventDate);
                    customerEvent.setLastModifiedBy5(lastModifiedBy);
                    customerEvent.setLastModifiedDate5(lastModifiedDate);
                    break;
                case 6:
                    customerEvent.setScheduleEvent6(eventDate);
                    customerEvent.setLastModifiedBy6(lastModifiedBy);
                    customerEvent.setLastModifiedDate6(lastModifiedDate);
                    break;
                case 7:
                    customerEvent.setScheduleEvent7(eventDate);
                    customerEvent.setLastModifiedBy7(lastModifiedBy);
                    customerEvent.setLastModifiedDate7(lastModifiedDate);
                    break;
                case 8:
                    customerEvent.setScheduleEvent8(eventDate);
                    customerEvent.setLastModifiedBy8(lastModifiedBy);
                    customerEvent.setLastModifiedDate8(lastModifiedDate);
                    break;
                case 9:
                    customerEvent.setScheduleEvent9(eventDate);
                    customerEvent.setLastModifiedBy9(lastModifiedBy);
                    customerEvent.setLastModifiedDate9(lastModifiedDate);
                    break;
                case 10:
                    customerEvent.setScheduleEvent10(eventDate);
                    customerEvent.setLastModifiedBy10(lastModifiedBy);
                    customerEvent.setLastModifiedDate10(lastModifiedDate);
                    break;
                case 11:
                    customerEvent.setScheduleEvent11(eventDate);
                    customerEvent.setLastModifiedBy11(lastModifiedBy);
                    customerEvent.setLastModifiedDate11(lastModifiedDate);
                    break;
                case 12:
                    customerEvent.setScheduleEvent12(eventDate);
                    customerEvent.setLastModifiedBy12(lastModifiedBy);
                    customerEvent.setLastModifiedDate12(lastModifiedDate);
                    break;
                case 13:
                    customerEvent.setScheduleEvent13(eventDate);
                    customerEvent.setLastModifiedBy13(lastModifiedBy);
                    customerEvent.setLastModifiedDate13(lastModifiedDate);
                    break;
                case 14:
                    customerEvent.setScheduleEvent14(eventDate);
                    customerEvent.setLastModifiedBy14(lastModifiedBy);
                    customerEvent.setLastModifiedDate14(lastModifiedDate);
                    break;
                case 15:
                    customerEvent.setScheduleEvent15(eventDate);
                    customerEvent.setLastModifiedBy15(lastModifiedBy);
                    customerEvent.setLastModifiedDate15(lastModifiedDate);
                    break;
                default:
                    System.out.println("Event is not available");
            }
        }

        CorporateCustomer corporateCustomer = (CorporateCustomer) session.getAttribute("corporateCustomer");

        int result = this.customerService.addCorporateCustomer(corporateCustomer, customerEvent);

        session.removeAttribute("corporateCustomer");
//        map.addAttribute("customerName", "");
//        map.addAttribute("paymentTypeId", corporateCustomer.getCorporate().getPaymentTypeId());

        if (result == 0) {
            return "redirect:/corporate/listCorporateCustomer.htm?msg=Fail to save customer data";
        }
        return "redirect:/corporate/listCorporateCustomer.htm?customerName=&paymentTypeId=" + corporateCustomer.getCorporate().getPaymentTypeId();
    }

    @RequestMapping(value = "/corporate/listCorporateCustomer.htm")
    public String showListCorporatePage(
            @RequestParam(value = "customerName", required = true, defaultValue = "") String customerName,
            @RequestParam(value = "paymentTypeId", required = true, defaultValue = "0") int corporateId,
            ModelMap map) {
        System.out.println("inside list corporate page");
        map.addAttribute("listCorporateData", this.customerService.getCorporateCustomerList(customerName, corporateId));

        List<Event> eventList = this.customerService.getEventList(corporateId);

        if (eventList == null && corporateId != 0) {
            return "redirect:../corporate/listCorporateCustomer.htm?msg=Please Contact technical team.<br/>Events are conflict.";
        } else {
            map.addAttribute("eventList", eventList);
            map.addAttribute("paymentTypeId", corporateId);
            map.addAttribute("customerName", customerName);
            map.addAttribute("excelDownload", 0);

            return "/corporate/listCorporateCustomer";
        }
    }

    @RequestMapping(value = "/corporate/editCorporateCustomer.htm", method = RequestMethod.GET)
    public String showEditCorporatePage(HttpServletRequest request, ModelMap map) {
        int coCustomerId = ServletRequestUtils.getIntParameter(request, "coCustomerId", 0);
        System.out.println("inside edit corporate page");
        CorporateCustomerEvent events = this.customerService.getCorporateCustomerEventData(coCustomerId);
        List<EventStatus> eventStatusList = this.customerService.getEventStatusList();
        map.addAttribute("eventStatusList", eventStatusList);
        map.addAttribute("coCustomerId", coCustomerId);
        map.addAttribute("events", events);
        map.addAttribute("result", 2);

        return "/corporate/editCorporateCustomer";
    }

//    @RequestMapping(value = "/corporate/editCorporateCustomer.htm", method = RequestMethod.POST)
//    public String editCorporatePage(@ModelAttribute("events") CorporateCustomerEvent coCustomerEvents, HttpServletRequest request, ModelMap map) throws ServletRequestBindingException, ParseException {
//        System.out.println("inside edit corporate page:Post");
//        CorporateCustomer customer = new CorporateCustomer();
//        customer.setCorporateCustomerId(ServletRequestUtils.getIntParameter(request, "corporateCustomer.corporateCustomerId"));
//        coCustomerEvents.setCorporateCustomer(customer);
//        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yy");
//        Date eventDate = null;
//        for (int i = 1; i <= 15; i++) {
//            if (!ServletRequestUtils.getStringParameter(request, "scheduleEventT" + i).equals("")) {
//                eventDate = sdf.parse(ServletRequestUtils.getStringParameter(request, "scheduleEventT" + i));
//            } else {
//                eventDate = null;
//            }
//            switch (i) {
//                case 1:
//                    coCustomerEvents.setScheduleEvent1(eventDate);
//                    break;
//                case 2:
//                    coCustomerEvents.setScheduleEvent2(eventDate);
//                    break;
//                case 3:
//                    coCustomerEvents.setScheduleEvent3(eventDate);
//                    break;
//                case 4:
//                    coCustomerEvents.setScheduleEvent4(eventDate);
//                    break;
//                case 5:
//                    coCustomerEvents.setScheduleEvent5(eventDate);
//                    break;
//                case 6:
//                    coCustomerEvents.setScheduleEvent6(eventDate);
//                    break;
//                case 7:
//                    coCustomerEvents.setScheduleEvent7(eventDate);
//                    break;
//                case 8:
//                    coCustomerEvents.setScheduleEvent8(eventDate);
//                    break;
//                case 9:
//                    coCustomerEvents.setScheduleEvent9(eventDate);
//                    break;
//                case 10:
//                    coCustomerEvents.setScheduleEvent10(eventDate);
//                    break;
//                case 11:
//                    coCustomerEvents.setScheduleEvent11(eventDate);
//                    break;
//                case 12:
//                    coCustomerEvents.setScheduleEvent12(eventDate);
//                    break;
//                case 13:
//                    coCustomerEvents.setScheduleEvent13(eventDate);
//                    break;
//                case 14:
//                    coCustomerEvents.setScheduleEvent14(eventDate);
//                    break;
//                case 15:
//                    coCustomerEvents.setScheduleEvent15(eventDate);
//                    break;
//                default:
//                    System.out.println("Event is not available");
//            }
//        }
//
//        int result = this.customerService.editCorporateCustomerEventData(coCustomerEvents);
//        CorporateCustomerEvent events = this.customerService.getCorporateCustomerEventData(coCustomerEvents.getCorporateCustomerEventId());
//        map.addAttribute("coCustomerId", coCustomerEvents.getCorporateCustomerEventId());
//        map.addAttribute("events", events);
//        map.addAttribute("result", result);
//
//        return "/corporate/editCorporateCustomer";
//    }
    @RequestMapping(value = "ajaxCallForeditCorporate.htm")
    public @ResponseBody
    String editCorporatePage(HttpServletRequest request) throws ParseException {
        int eventId = ServletRequestUtils.getIntParameter(request, "eventId", 0);
        String eventDate = ServletRequestUtils.getStringParameter(request, "eventDate", "");
        int eventStatus = ServletRequestUtils.getIntParameter(request, "eventStatus", 0);
        int corporateId = ServletRequestUtils.getIntParameter(request, "corporateId", 0);
        System.out.println("inside Ajaxedit corporate page:Post");

        boolean result = this.customerService.updateEvent(corporateId, eventId, eventDate, eventStatus);

        Gson gson = new Gson();
        String json = gson.toJson(true);
        return json;
    }

    @RequestMapping(value = "ajaxCallForEventListByCorporateId.htm")
    public @ResponseBody
    String eventListPage(HttpServletRequest request) throws ParseException {
        int corporateId = ServletRequestUtils.getIntParameter(request, "corporateId", 0);
        System.out.println("inside Ajax event list page:Post");
        List<Event> events = this.customerService.getEventList(corporateId);
        Gson gson = new Gson();
        String json = gson.toJson(events);
        return json;
    }

    @RequestMapping(value = "ajaxCallForEventEdit.htm")
    public @ResponseBody
    String editEventPage(HttpServletRequest request) throws ParseException {
        int eventId = ServletRequestUtils.getIntParameter(request, "eventId", 0);
        String eventDescription = ServletRequestUtils.getStringParameter(request, "eventDescription", "Comming soon");
        int corporateId = ServletRequestUtils.getIntParameter(request, "corporateId", 0);
        System.out.println("inside Ajax event edit page:Post");
        Event event = new Event();
        event.setEventId(eventId);
        event.setEventDescription(eventDescription);
        PaymentType corporate = new PaymentType();
        corporate.setPaymentTypeId(corporateId);
        event.setCorporate(corporate);
        event.setActive(1);
        boolean result = this.customerService.editEvent(event);
        Gson gson = new Gson();
        String json = gson.toJson(true);
        return json;
    }

    @RequestMapping(value = "/corporate/corporateCustomerExcel.htm")
    public ModelAndView buildExcelForCorporateCustomer(
            @RequestParam(value = "excelDownload", required = true, defaultValue = "0") int excelDownload,
            @RequestParam(value = "customerName", required = true, defaultValue = "") String customerName,
            @RequestParam(value = "paymentTypeId", required = true, defaultValue = "0") int corporateId,
            ModelMap modelMap) {

        ModelAndView mvc = null;
        System.out.println("ed:" + excelDownload);
        List<Map<String, Object>> coCustomerList = this.customerService.getCorporateCustomerExcelData(customerName, corporateId);
        if (excelDownload == 1 && coCustomerList.size() > 0) {
            String corporateName = coCustomerList.get(0).get("PAYMENT_TYPE_NAME").toString();

            SimpleDateFormat df = new SimpleDateFormat("MM-dd-yy");
            WorkSheet thisWorkSheet = new WorkSheet();
            thisWorkSheet.setTitle("Corporate Customer List");
            ArrayList<Parameter> parameters = new ArrayList<Parameter>();
            parameters.add(new Parameter("Customer Name(Prefix)", customerName));
            parameters.add(new Parameter("Corporate Name", corporateName.toString().trim()));
            thisWorkSheet.setParameters(parameters);

            ArrayList<CellInfo> headers = new ArrayList<CellInfo>();
            headers.add(new CellInfo("Corporate Customer Id", CellInfo.TEXT));
            headers.add(new CellInfo("Employee Code", CellInfo.TEXT));
            headers.add(new CellInfo("Customer Name", CellInfo.TEXT));
            headers.add(new CellInfo("Phone Number", CellInfo.TEXT));
            headers.add(new CellInfo("Email Address", CellInfo.TEXT));
            headers.add(new CellInfo("Department", CellInfo.TEXT));
            headers.add(new CellInfo("Office location", CellInfo.TEXT));
            headers.add(new CellInfo("Designation", CellInfo.TEXT));

            headers.add(new CellInfo("Round 1 Score", CellInfo.TEXT));
            headers.add(new CellInfo("Round 1 Risk", CellInfo.TEXT));

            headers.add(new CellInfo("CategoryA", CellInfo.TEXT));
            headers.add(new CellInfo("CategoryB", CellInfo.TEXT));
            headers.add(new CellInfo("CategoryC", CellInfo.TEXT));
            headers.add(new CellInfo("Corporate", CellInfo.TEXT));

            headers.add(new CellInfo("Event1", CellInfo.TEXT));
            headers.add(new CellInfo("Event1 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event1 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event2", CellInfo.TEXT));
            headers.add(new CellInfo("Event2 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event2 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event3", CellInfo.TEXT));
            headers.add(new CellInfo("Event3 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event3 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event4", CellInfo.TEXT));
            headers.add(new CellInfo("Event4 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event4 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event5", CellInfo.TEXT));
            headers.add(new CellInfo("Event5 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event5 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event6", CellInfo.TEXT));
            headers.add(new CellInfo("Event6 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event6 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event7", CellInfo.TEXT));
            headers.add(new CellInfo("Event7 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event7 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event8", CellInfo.TEXT));
            headers.add(new CellInfo("Event8 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event8 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event9", CellInfo.TEXT));
            headers.add(new CellInfo("Event9 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event9 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event10", CellInfo.TEXT));
            headers.add(new CellInfo("Event10 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event10 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event11", CellInfo.TEXT));
            headers.add(new CellInfo("Event11 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event11 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event12", CellInfo.TEXT));
            headers.add(new CellInfo("Event12 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event12 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event13", CellInfo.TEXT));
            headers.add(new CellInfo("Event13 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event13 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event14", CellInfo.TEXT));
            headers.add(new CellInfo("Event14 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event14 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            headers.add(new CellInfo("Event15", CellInfo.TEXT));
            headers.add(new CellInfo("Event15 Date", CellInfo.TEXT));
            headers.add(new CellInfo("Event15 Status", CellInfo.TEXT));
            headers.add(new CellInfo("Last modified By", CellInfo.TEXT));
            headers.add(new CellInfo("Last Modified Date", CellInfo.TEXT));

            ArrayList<BodyRow> rows = new ArrayList<BodyRow>();
            BodyRow headerRow = new BodyRow();
            headerRow.setValues(headers);
            headerRow.setRowColour(Colour.LAVENDER);
            rows.add(headerRow);
            String eventDate = "";
            int eventStatus = 0;
            String lastModifiedDate = "";

            for (Map<String, Object> data : coCustomerList) {
                BodyRow tmpRow = new BodyRow();
                ArrayList<CellInfo> values = new ArrayList<CellInfo>();
                tmpRow.setRowColour(Colour.WHITE);
                values.add(new CellInfo(Integer.parseInt(data.get("CORPORATE_CUSTOMER_ID").toString()), CellInfo.INTEGER, 4000));
                values.add(new CellInfo(data.get("EMPLOYEE_ID").toString(), CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("NAME"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("PHONE"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("EMAIL"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("DEPARTMENT"), CellInfo.TEXT, 7600));
                values.add(new CellInfo(data.get("OFFICE_LOCATION"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("DESIGNATION"), CellInfo.TEXT, 4000));

                values.add(new CellInfo(data.get("SCORE_ROUND_1"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("RISK_ROUND_1"), CellInfo.TEXT, 4000));

                values.add(new CellInfo(data.get("CATEGORY_A"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("CATEGORY_B"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("CATEGORY_C"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("PAYMENT_TYPE_NAME"), CellInfo.TEXT, 4000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_1"));
                    eventStatus = Integer.parseInt(data.get("STATUS_1").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE1"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_1"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY1"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));


                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_2"));
                    eventStatus = Integer.parseInt(data.get("STATUS_2").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE2"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_2"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY2"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_3"));
                    eventStatus = Integer.parseInt(data.get("STATUS_3").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE3"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_3"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY3"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_4"));
                    eventStatus = Integer.parseInt(data.get("STATUS_4").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE4"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_4"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY4"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_5"));
                    eventStatus = Integer.parseInt(data.get("STATUS_5").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE5"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_5"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY5"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_6"));
                    eventStatus = Integer.parseInt(data.get("STATUS_6").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE6"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_6"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY6"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_7"));
                    eventStatus = Integer.parseInt(data.get("STATUS_7").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE7"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_7"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY7"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_8"));
                    eventStatus = Integer.parseInt(data.get("STATUS_8").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE8"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_8"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY8"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_9"));
                    eventStatus = Integer.parseInt(data.get("STATUS_9").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE9"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_9"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY9"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_10"));
                    eventStatus = Integer.parseInt(data.get("STATUS_10").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE10"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_10"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY10"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_11"));
                    eventStatus = Integer.parseInt(data.get("STATUS_11").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE11"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_11"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY11"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_12"));
                    eventStatus = Integer.parseInt(data.get("STATUS_12").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE12"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_12"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY12"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_13"));
                    eventStatus = Integer.parseInt(data.get("STATUS_13").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE13"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_13"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY13"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_14"));
                    eventStatus = Integer.parseInt(data.get("STATUS_14").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE14"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_14"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY14"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));

                try {
                    eventDate = df.format(data.get("SCHEDULE_EVENT_15"));
                    eventStatus = Integer.parseInt(data.get("STATUS_15").toString());
                    lastModifiedDate = df.format(data.get("LAST_MODIFIED_DATE15"));
                } catch (Exception e) {
                    eventDate = "";
                    eventStatus = 0;
                    lastModifiedDate = "";
                }
                values.add(new CellInfo(data.get("EVENT_ID_15"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(eventDate, CellInfo.TEXT, 4000));
                values.add(new CellInfo((eventStatus == 0) ? "Not yet" : (eventStatus == 1) ? "Yes" : (eventStatus == 2) ? "ReScheduled" : (eventStatus == 3) ? "Delayed" : (eventStatus == 4) ? "Declined" : "Left Organization", CellInfo.TEXT, 4000));
                values.add(new CellInfo(data.get("LAST_MODIFIED_BY15"), CellInfo.TEXT, 4000));
                values.add(new CellInfo(lastModifiedDate, CellInfo.TEXT, 7000));



                tmpRow.setValues(values);
                rows.add(tmpRow);
            }

            thisWorkSheet.setBodyRows(rows);
            ArrayList<WorkSheet> finalWorkBook = new ArrayList<WorkSheet>();
            finalWorkBook.add(thisWorkSheet);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("WorkBook", finalWorkBook);
            map.put("FileName", corporateName + " Customer List");
            mvc = new ModelAndView("exportReportExelController", "map", map);
        } else {
            mvc = new ModelAndView("redirect:/corporate/listCorporateCustomer.htm?customerName=" + customerName + "&paymentTypeId=" + corporateId);
        }
        return mvc;
    }

    @RequestMapping(value = "/corporate/uploadCorporateCustomer.htm", method = RequestMethod.GET)
    public String showUploadCorporateCustomer(ModelMap modelMap) {
        System.out.println("upload Get");
        FileUpload fileUpload = new FileUpload();
        modelMap.addAttribute("fileUpload", fileUpload);

        int corporateId = 1;
        List<Event> eventList = this.customerService.getEventList(corporateId);
        modelMap.addAttribute("eventList", eventList);
        modelMap.addAttribute("corporateId", corporateId);

        return "/corporate/uploadCorporateCustomer";
    }

    @RequestMapping(value = "/corporate/getEventList.htm", method = RequestMethod.POST)
    public String getEventList(HttpServletRequest request, ModelMap modelMap) {
        int corporateId = ServletRequestUtils.getIntParameter(request, "paymentTypeId", 1);
        System.out.println("upload Get");
        FileUpload fileUpload = new FileUpload();
        modelMap.addAttribute("fileUpload", fileUpload);

        List<Event> eventList = this.customerService.getEventList(corporateId);
        modelMap.addAttribute("eventList", eventList);
        modelMap.addAttribute("corporateId", corporateId);

        return "/corporate/uploadCorporateCustomer";
    }

    @RequestMapping(value = "/corporate/uploadCorporateCustomer.htm", method = RequestMethod.POST)
    public String postUploadedCorporateCustomer(@ModelAttribute("fileUpload") FileUpload fileUpload, HttpServletRequest request, ModelMap modelMap) {
        System.out.println("upload Post for confirm");
        Map<String, Object> map = this.customerService.getCorporateCustomer(fileUpload);
        List<CorporateCustomer> corporateCustommerList = (List) map.get("corporateCustomerList");
        List<CorporateCustomerEvent> corporateCustommerEventList = (List) map.get("corporateCustomerEventList");

//        List<Event> events = this.customerService.getEventList();

//        modelMap.addAttribute("events", events);
        modelMap.addAttribute("corporateCustommerList", corporateCustommerList);
        modelMap.addAttribute("corporateCustommerEventList", corporateCustommerEventList);
        return "/corporate/confirmUploadCorporateCustomer";
    }

    @RequestMapping(value = "/corporate/cancelCorporateCustomer.htm")
    public String cancelUploadedCorporateCustomer() {
        System.out.println("cancel upload");
        return "/corporate/uploadCorporateCustomer";
    }

    @RequestMapping(value = "/corporate/saveCorporateCustomerData.htm", method = RequestMethod.POST)
    public String saveCorporateCustomerData(ModelMap modelMap, HttpSession session) {

        List<CorporateCustomer> corporateCustommerList = (List<CorporateCustomer>) session.getAttribute("corporateCustommerList");
        List<CorporateCustomerEvent> corporateCustommerEventList = (List<CorporateCustomerEvent>) session.getAttribute("corporateCustommerEventList");

//        List<CorporateCustomer> corporateCustommerList = (List<CorporateCustomer>) modelMap.get("corporateCustommerList");
//        List<CorporateCustomerEvent> corporateCustommerEventList = (List<CorporateCustomerEvent>) modelMap.get("corporateCustommerEventList");


        try {
            int rowsUploaded = this.customerService.saveCorporateCustomerData(corporateCustommerList, corporateCustommerEventList);
            return "redirect:/corporate/listCorporateCustomer.htm?msg=" + rowsUploaded + " rows succesfully uploaded";
        } catch (CouldNotSaveToDataBaseException ce) {
            return "redirect:/corporate/listCorporateCustomer.htm?msg=" + ce.getMessage();
        }

    }

    @RequestMapping(value = "/corporate/addCorporate.htm", method = RequestMethod.GET)
    public String showAddCorporatePage(ModelMap map) {
        System.out.println("add corporate: GET");
        PaymentType corporate = new PaymentType();
        map.addAttribute("corporate", corporate);
        return "/corporate/addCorporate";
    }

    @RequestMapping(value = "/corporate/addCorporate.htm", method = RequestMethod.POST)
    public String addCorporatePage(@ModelAttribute("corporate") PaymentType corporate, ModelMap map) {
        System.out.println("add corporate: POST");
        int result = this.customerService.addCorporate(corporate);
        List<PaymentType> corporateList = this.customerService.getPaymentTypeList();
        map.addAttribute("corporateList", corporateList);
        return "/corporate/listCorporate";
    }

    @RequestMapping(value = "/corporate/listCorporate.htm", method = RequestMethod.GET)
    public String showListCorporatePage(ModelMap map) {
        System.out.println("list corporate:GET");

        List<PaymentType> corporateList = this.customerService.getPaymentTypeList();
        map.addAttribute("corporateList", corporateList);
        return "/corporate/listCorporate";
    }

    @RequestMapping(value = "/corporate/editCorporate.htm", method = RequestMethod.GET)
    public String showEditCorporatePage(@RequestParam(value = "corporateId") int corporateId, ModelMap map) {
        System.out.println("edit corporate: GET");
        PaymentType corporate = this.customerService.getCorporateById(corporateId);
        map.addAttribute("corporate", corporate);
        return "/corporate/editCorporate";
    }

    @RequestMapping(value = "/corporate/editCorporate.htm", method = RequestMethod.POST)
    public String editCorporatePage(@ModelAttribute("corporate") PaymentType corporate, ModelMap map) {
        System.out.println("edit corporate: GET");
        int result = this.customerService.editCorporate(corporate);

        List<PaymentType> corporateList = this.customerService.getPaymentTypeList();
        map.addAttribute("corporateList", corporateList);
        return "/corporate/listCorporate";
    }
}
